package Udp;

import java.io.IOException;
import java.net.*;

public class udp0 {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket=new DatagramSocket(9998);
        byte[] bytes="hello,吃火锅".getBytes();
        DatagramPacket packet=
        new DatagramPacket(bytes,bytes.length, InetAddress.getByName("192.168.43.97"),9999);
        socket.send(packet);



        byte[] bytes1=new byte[1024];
        DatagramPacket packet1=new DatagramPacket(bytes1,bytes1.length);
        System.out.println("等待接收");
        socket.receive(packet1);
        int paccketlenght=packet1.getLength();//接收到的实际长度
        bytes1= packet1.getData();//接收的数据
        String str=new String(bytes1,0,paccketlenght);
        System.out.println(str);
        System.out.println("端口A结束");
        socket.close();
    }
}
